<template>
  <div class="index">
    <section @scroll='setScrollTop($event)'>
      <router-view></router-view>
    </section>
    <footer>
      <router-link to="/home" class="home">
        <span class=""></span>
        <b>首页</b>
      </router-link>
      <router-link to="/column" class="column">
        <span class=""></span>
        <b>专栏</b>
      </router-link>
      <router-link to="/groupbuy" class="groupbuy">
        <span class=""></span>
        <b>团购</b>
      </router-link>
      <router-link to="/my" class="my">
        <span class=""></span>
        <b>我的</b>
      </router-link>
    </footer>
    <!-- <div class="tixing">{{tixing}}
      <span v-show="show">下单完成</span>
    </div> -->
  </div>
</template>
<script>
  export default {
    data() {
      return {
        type: '',
        tixing: '',
        show: false,

      }
    },
    methods: {
      justUserType() { //判断用户是否通过医生认证
        if (localStorage.getItem("loginMobile")) {
          this.userid = localStorage.getItem("loginMobile");
          this.$api.get(this.$api.baseURLSchool, "select_cid/user/" + this.userid, {}, r => {
            localStorage.setItem("type", JSON.stringify(r.data.info.type));
            if (r.data.info.type == 'doctor') {
              localStorage.setItem("type_sub", JSON.stringify(r.data.info.type_sub));
            }
            this.type = r.data.info.type;
          }, err => {
            console.log(err);
          })
        }
      },
      setScrollTop(e) {
        localStorage.setItem("scrollTop", e.target.scrollTop);
      },

      tabToggle() {
        if (this.tixing = '') {
          this.show = false
        }
        this.$api.get(this.$api.baseURLSchool, "new_order", {}, r => {
          this.tixing = r.data.info.order_num
          if (r.data.info.order_num == undefined) {
            this.show = false
          }
          this.show = true
        }, err => {
          console.log(err);
        })
      },
      countDown(times, index) {
        let timer = setInterval(() => {
          // this.tabToggle()
        }, 10000);
      },



    },
    created() {
      this.countDown()
      this.justUserType()
    },
    //history模式下 返回会触发
    beforeRouteEnter(to, from, next) {
      next();
    },
    beforeRouteLeave(to, from, next) {
      next();
    },
    //history模式下 返回会触发
    activated() {
      this.justUserType();
      if (localStorage.getItem("scrollTop")) {
        $('section').scrollTop(localStorage.getItem("scrollTop"));
      }
    },
    mounted() {
      localStorage.setItem("scrollTop", 0);
    },

  }

</script>
<style lang="scss">
  .tixing {
    position: absolute;
    bottom: 10%;
    width: 100%;
    left: 50%;
    font-size: 16px;
    transform: translateX(-50%);
    color: red;
    animation: danmu 10s linear infinite;
  }

  @keyframes danmu {
    from {
      left: 100%;
      transform: translateX(0);
    }

    to {
      left: 0;
      transform: translateX(-100%);
    }
  }

</style>
